﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            int intnum;         //读取文件中有多少个数据
            tosend a = new tosend();            //实例化接口
            StreamReader reader = new StreamReader("E://stu00.txt", System.Text.Encoding.Default);          //以中文编码格式打开文件
            string num = reader.ReadLine();         //逐行读取
            intnum = Convert.ToInt32(num);              //字符转换
            for (int i = 0; i < intnum; i++)
            {
                string message = reader.ReadLine();             //逐行读取
                string[] kk = message.Split(' ');               //根据空格切割
                string b = "http://utf8.sms.webchinese.cn/?Uid=sise&Key=ab8d638d05b27cf5757f&smsMob=" + kk[kk.Length - 1] + "&smsText=" + kk[1] + "同学" + kk[0] + "参加2013年高等教育考试，被华软学院软件工程系" + kk[kk.Length - 2] + "专业方向录取，向您表示祝贺与欢迎！";
                //上面这个用来组成接口网站
                System.Text.Encoding.UTF8.GetBytes(b);          //进行UTF8编码
                string c = a.GetHtmlFromUrl(b);         //调用接口
                if (c=="-1")                    //错误判断
                    Console.Write("wrong1");
                if (c == "-2")
                    Console.Write("wrong2");
                if (c == "-3")
                    Console.Write("wrong3");
                if (c == "-11")
                    Console.Write("wrong4");
                if (c == "-14")
                    Console.Write("wrong5");
                if (c == "-4")
                    Console.Write("wrong6");
                if (c == "-41")
                    Console.Write("wrong7");
                if (c == "-42")
                    Console.Write("wrong8");
            }
            reader.Close();
            Console.WriteLine("【信息发送成功！】");
        }
    }
    class tosend                        //网站所给接口
    {
        public string GetHtmlFromUrl(string url)
        {
            string strRet = null;

            if (url == null || url.Trim().ToString() == "")
            {
                return strRet;
            }
            string targeturl = url.Trim().ToString();
            try
            {
                HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);
                hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
                hr.Method = "GET";
                hr.Timeout = 30 * 60 * 1000;
                WebResponse hs = hr.GetResponse();
                Stream sr = hs.GetResponseStream();
                StreamReader ser = new StreamReader(sr, Encoding.Default);
                strRet = ser.ReadToEnd();
            }
            catch (Exception ex)
            {
                strRet = null;
            }
            return strRet;
        }
    }
}
